package com.zyh.kaoshi.test4;

/**
 * @Author zyh
 * @Date 2024/8/10 11:39
 * @Description
 */

public class test4 {
    public static void main(String[] args) {
        Runnable task=new Runnable() {
            private int num=100;
            @Override
            public  void run() {
                while (true){
                    synchronized (this) {
                        if (num<=0){
                            break;
                        }
                        try {
                            Thread.sleep(10);
                            System.out.println(Thread.currentThread().getName()+"卖出第"+num+"张票");
                            num--;
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                    }
                }
            }
        };
        for (int i = 1; i < 6; i++) {
            new Thread(task,"售票点"+i).start();
        }
    }
}

